package com.cug.smartranch.animal.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cug.smartranch.animal.admin.dto.req.FeedDetailPageQueryReqDTO;
import com.cug.smartranch.animal.admin.dto.req.FeedPlanPageQueryReqDTO;
import com.cug.smartranch.animal.admin.dto.req.PlanSaveReqDTO;
import com.cug.smartranch.animal.admin.dto.req.PlanUpdateReqDTO;
import com.cug.smartranch.animal.admin.dto.resp.FeedDetailPageQueryRespDTO;
import com.cug.smartranch.animal.admin.dto.resp.FeedPlanPageQueryRespDTO;
import com.cug.smartranch.animal.admin.service.FeedPlanService;
import com.cug.smartranch.framework.result.Result;
import com.cug.smartranch.framework.web.Results;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 喂养设备记录控制层
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "喂养计划管理")
@RequestMapping("/api/feed_admin/feedPlan")
public class FeedPlanController {
    private final FeedPlanService feedPlanService;

    @Operation(summary = "用户创建喂养计划记录")
    @PostMapping("/create")
    public Result<Void> createPlan(@RequestBody PlanSaveReqDTO requestParam) {
        feedPlanService.createPlan(requestParam);
        return Results.success();
    }

    @Operation(summary = "修改喂养计划的投放量")
    @PostMapping("/update")
    public Result<Void> updatePlan(@RequestBody PlanUpdateReqDTO requestParam) {
        feedPlanService.updatePlan(requestParam);
        return Results.success();
    }


    @Operation(summary = "查询前执行未完成的喂养计划记录")
    @PostMapping("/execute")
    public Result<Void> executeUncompletedPlan() {
        feedPlanService.executeUncompletedPlan();
        return Results.success();
    }

    @Operation(summary = "喂养计划分页查询")
    @GetMapping("/select/all")
    public Result<IPage<FeedPlanPageQueryRespDTO>> selectAllFeedPlan(FeedPlanPageQueryReqDTO requestParam) {
        IPage<FeedPlanPageQueryRespDTO> list = feedPlanService.selectAllFeedPlan(requestParam);
        return Results.success(list);
    }

    @Operation(summary = "删除喂养计划")
    @PostMapping("/delete")
    public Result<Void> deletePlan(@RequestParam Long id) {
        feedPlanService.deletePlan(id);
        return Results.success();
    }
}
